package cn.com.sinosoft.exam.page;

import org.apache.commons.lang.StringUtils;
import org.springframework.web.context.request.NativeWebRequest;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * 
 * 分页参数
 * @author xl
 *
 */
@ApiModel("分页参数")
public class PageParam {
	
	/**
	 * 页码
	 */
	@ApiModelProperty("页码")
	int page;
	
	/**
	 * 记录数
	 */
	@ApiModelProperty("条目")
	int limit;
	
	private PageParam(int page,int limit) {
		this.page = page;
		this.limit = limit;
	}
	
	/**
	 * 构建分页参数
	 * @param params
	 * @return
	 */
	public static PageParam getInstance(int page, int limit, NativeWebRequest webRequest){
        if(StringUtils.isNotBlank(webRequest.getParameter("page"))){
        	page = Integer.parseInt(webRequest.getParameter("page"));
        }
        if(StringUtils.isNotBlank(webRequest.getParameter("limit"))){
        	limit = Integer.parseInt(webRequest.getParameter("limit"));
        }
		return new PageParam(page,limit);
	}
	
	/**
	 * 构建分页参数
	 * @param params
	 * @return
	 */
	public static PageParam getInstance(int page, int limit){
		return new PageParam(page,limit);
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

}
